function sendVerificationCode() {
  const email = document.getElementById('email').value;
  if (email) {
    fetch('/send-code', {
      method: 'POST',
      headers: {
        'Content-Type': 'application/json'
      },
      body: JSON.stringify({ email: email })
    })
      .then(response => response.text())
      .then(data => {
        alert(data);
      })
      .catch(error => {
        console.error('Error:', error);
      });
  } else {
    alert('请输入邮箱地址');
  }
}

document.getElementById('registerForm').addEventListener('submit', function (event) {
  event.preventDefault();
  const verificationCode = document.getElementById('verificationCode').value;
  const password = document.getElementById('password').value;
  const confirmPassword = document.getElementById('confirmPassword').value;

  fetch('/verify-code', {
    method: 'POST',
    headers: {
      'Content-Type': 'application/json'
    },
    body: JSON.stringify({ code: verificationCode })
  })
    .then(response => response.text())
    .then(data => {
      if (data === '验证码正确') {
        if (password !== confirmPassword) {
          alert('密码和确认密码不匹配');
        } else {
          alert('注册成功');
          // 在这里添加注册逻辑
        }
      } else {
        alert('验证码错误');
      }
    })
    .catch(error => {
      console.error('Error:', error);
    });
});
